package cn.swpu.blog.config;

import cn.swpu.blog.schedule.RedisScheduleJob;
import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author 冰翔
 * @Date 2021/3/3 21:46
 */
@Configuration
public class QuartzConfig {
    private static final String LIKE_TASK_IDENTITY = "RedisScheduleJob";

    @Bean
    public JobDetail quartzDetail(){
        return JobBuilder.newJob(RedisScheduleJob.class).withIdentity(LIKE_TASK_IDENTITY).storeDurably().build();
    }

    @Bean
    public Trigger quartzTrigger(){
        SimpleScheduleBuilder scheduleBuilder = SimpleScheduleBuilder.simpleSchedule()
//                .withIntervalInSeconds(10)  //设置时间周期单位秒
                .withIntervalInHours(24)  //两个小时执行一次
                .repeatForever();
        return TriggerBuilder.newTrigger().forJob(quartzDetail())
                .withIdentity(LIKE_TASK_IDENTITY)
                .withSchedule(scheduleBuilder)
                .build();
    }
}
